home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc Development Framework / ODFDev / ODF / Framewrk / FWPart / Sources / FWSelect.cpp < prev    next >
Encoding:
Text File  |  1995-11-08  |  12.5 KB  |  403 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWSelect.cpp
  4. //    Release Version:    $ 1.0d11 $
  5. //
  6. //    Copyright:    © 1995 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "FWFrameW.hpp"
  11.  
  12. #ifndef FWSELECT_H
  13. #include "FWSelect.h"
  14. #endif
  15.  
  16. #ifndef FWUTIL_H
  17. #include "FWUtil.h"
  18. #endif
  19.  
  20. #ifndef FWPRESEN_H
  21. #include "FWPresen.h"
  22. #endif
  23.  
  24. #ifndef FWPART_H
  25. #include "FWPart.h"
  26. #endif
  27.  
  28. #ifndef FWPRMISE_H
  29. #include "FWPrmise.h"
  30. #endif
  31.  
  32. #ifndef FWCLNINF_H
  33. #include "FWClnInf.h"
  34. #endif
  35.  
  36. #ifndef FWFRAME_H
  37. #include "FWFrame.h"
  38. #endif
  39.  
  40. // ----- OS Layer Includes -----
  41.  
  42. #ifndef FWODGEOM_H
  43. #include "FWODGeom.h"
  44. #endif
  45.  
  46. #ifndef FWEVENT_H
  47. #include "FWEvent.h"
  48. #endif
  49.  
  50. // ----- OpenDoc Includes -----
  51.  
  52. #ifndef SOM_ODStorageUnit_xh
  53. #include <StorageU.xh>
  54. #endif
  55.  
  56. #ifndef SOM_ODSession_xh
  57. #include <ODSessn.xh>
  58. #endif
  59.  
  60. #ifndef SOM_ODClipboard_xh
  61. #include <Clipbd.xh>
  62. #endif
  63.  
  64. #ifndef SOM_ODStorageUnitView_xh
  65. #include <SUView.xh>
  66. #endif
  67.  
  68. #ifndef SOM_ODShape_xh
  69. #include <Shape.xh>
  70. #endif
  71.  
  72. #ifndef SOM_ODFacet_xh
  73. #include <Facet.xh>
  74. #endif
  75.  
  76. #ifndef SOM_Module_OpenDoc_StdProps_defined
  77. #include <StdProps.xh>
  78. #endif
  79.  
  80. //========================================================================================
  81. // RunTime Info
  82. //========================================================================================
  83.  
  84. #if FW_LIB_EXPORT_PRAGMAS
  85. #pragma lib_export on
  86. #endif
  87.  
  88. #ifdef FW_BUILD_MAC
  89. #pragma segment FWFrameworkSelection
  90. #endif
  91.  
  92. FW_DEFINE_CLASS_M0(FW_CSelection)
  93.  
  94. //========================================================================================
  95. //    class FW_CSelection
  96. //========================================================================================
  97.  
  98. //----------------------------------------------------------------------------------------
  99. //    FW_CSelection::FW_CSelection
  100. //----------------------------------------------------------------------------------------
  101.  
  102. FW_CSelection::FW_CSelection(Environment* ev, FW_Boolean allowPublish, FW_Boolean allowSubscribe) :
  103.     fPresentation(NULL),
  104.     fAllowPublish(allowPublish),
  105.     fAllowSubscribe(allowSubscribe)
  106. {
  107. }
  108.  
  109. //----------------------------------------------------------------------------------------
  110. //    FW_CSelection::~FW_CSelection
  111. //----------------------------------------------------------------------------------------
  112.  
  113. FW_CSelection::~FW_CSelection()
  114. {
  115. }
  116.  
  117. //----------------------------------------------------------------------------------------
  118. //    FW_CSelection::ClearSelection
  119. //----------------------------------------------------------------------------------------
  120.  
  121. FW_Boolean FW_CSelection::ClearSelection(Environment* ev)
  122. {
  123. FW_UNUSED(ev);
  124.  
  125.     return FALSE;
  126. }
  127.  
  128. //----------------------------------------------------------------------------------------
  129. //    FW_CSelection::CreateSelectionFrameShape
  130. //----------------------------------------------------------------------------------------
  131.  
  132. ODShape* FW_CSelection::CreateSelectionFrameShape(Environment* ev) const
  133. {
  134.     return NULL;
  135. }
  136.  
  137. //----------------------------------------------------------------------------------------
  138. //    FW_CSelection::CreateSelectionOutline
  139. //----------------------------------------------------------------------------------------
  140. // By default just outline the shape returned by CreateSelectionShape
  141.  
  142. ODShape* FW_CSelection::CreateSelectionOutline(Environment* ev, ODFacet* facet, FW_CFrame* frame) const
  143. {
  144.     ODShape* outline = CreateSelectionShape(ev, facet, frame);
  145.     
  146.     if (!outline->IsEmpty(ev))
  147.         ::FW_OutlineODShape(ev, outline, FW_IntToFixed(1));
  148.     
  149.     return outline;
  150. }
  151.  
  152. //----------------------------------------------------------------------------------------
  153. //    FW_CSelection::IsSelectionPublishable
  154. //----------------------------------------------------------------------------------------
  155.  
  156. FW_Boolean FW_CSelection::IsSelectionPublishable(Environment* ev)
  157. {
  158.     return fAllowPublish;
  159. }
  160.  
  161. //----------------------------------------------------------------------------------------
  162. //    FW_CSelection::NewPromise
  163. //----------------------------------------------------------------------------------------
  164.  
  165. FW_CPromise* FW_CSelection::NewPromise(Environment* ev, 
  166.                                         ODUpdateID updateID,
  167.                                         FW_EStorageKinds storageKind, 
  168.                                         FW_CFrame* scopeFrame, 
  169.                                         ODCloneKind cloneKind)
  170. {
  171.     return NULL;
  172. }
  173.  
  174. //----------------------------------------------------------------------------------------
  175. //    FW_CSelection::DoExternalizeSelection
  176. //----------------------------------------------------------------------------------------
  177.  
  178. void FW_CSelection::DoExternalizeSelection(Environment* ev, 
  179.                                         ODStorageUnit* destinationSU, 
  180.                                         FW_CCloneInfo* cloneInfo)
  181. {
  182.     FW_DEBUG_MESSAGE("FW_CSelection::DoExternalizeSelection should never be called");
  183. }
  184.  
  185. //----------------------------------------------------------------------------------------
  186. //    FW_CSelection::PrivHandleExternalizeSelection
  187. //----------------------------------------------------------------------------------------
  188.  
  189. void FW_CSelection::PrivHandleExternalizeSelection(Environment* ev,
  190.                                                     FW_EStorageKinds storageKind,
  191.                                                     ODStorageUnit* destinationSU, 
  192.                                                     FW_CCloneInfo* cloneInfo)
  193. {
  194.     // ----- Add the needed properties first -----
  195.     GetPart(ev)->AddProperties(ev, destinationSU);
  196.     
  197.     ODUpdateID updateID = 0;
  198.     
  199.     GetPart(ev)->DeletePromise(ev, storageKind);
  200.     
  201.     if (storageKind == FW_kClipboardStorage)
  202.         updateID = GetSession(ev)->GetClipboard(ev)->GetUpdateID(ev);
  203.         
  204.     FW_CPromise* promise = NewPromise(ev, updateID, storageKind, cloneInfo->GetScopeFrame(ev), cloneInfo->GetCloneKind(ev));
  205.     
  206.     if (promise)
  207.     {
  208.         GetPart(ev)->SetPromise(ev, promise);
  209.         promise->PromisePropertiesAndValues(ev, destinationSU);
  210.     }
  211.     else
  212.     {
  213.         this->DoExternalizeSelection(ev, destinationSU, cloneInfo);
  214.     }
  215.     
  216.     // ----- If supported, write a shape property -----
  217.     FW_CAcquiredODShape aqSelectionShape = CreateSelectionFrameShape(ev);
  218.     if (((ODShape*)aqSelectionShape) != NULL)
  219.     {
  220.         // ----- Add the property. WriteShape will add the value
  221.         if (destinationSU->Exists(ev, kODPropFrameShape, (ODValueType)NULL, 0))
  222.         {
  223.             destinationSU->Focus(ev, kODPropFrameShape, 
  224.                                 kODPosUndefined, 
  225.                                    (ODValueType)NULL, 
  226.                                 (ODValueIndex)1, 
  227.                                 kODPosUndefined);
  228.             destinationSU->Remove(ev);                // remove the first value
  229.         }
  230.         else
  231.             destinationSU->AddProperty(ev, kODPropFrameShape);
  232.             
  233.         aqSelectionShape->WriteShape(ev, destinationSU);
  234.     }
  235. }
  236.  
  237. //----------------------------------------------------------------------------------------
  238. //    FW_CSelection::PrivHandleInternalizeSelection
  239. //----------------------------------------------------------------------------------------
  240.  
  241. FW_EInternalizeResult FW_CSelection::PrivHandleInternalizeSelection(Environment* ev, 
  242.                                                                     ODStorageUnit* sourceSU, 
  243.                                                                     FW_CCloneInfo* cloneInfo)
  244. {
  245.     FW_Boolean result = this->DoInternalizeSelection(ev, sourceSU, cloneInfo);
  246.     return result ? FW_kInternalizeContent : FW_kInternalizeFailed;
  247. }
  248.  
  249. //----------------------------------------------------------------------------------------
  250. //    FW_CSelection::PrivPostInternalizeSelection
  251. //----------------------------------------------------------------------------------------
  252.  
  253. void FW_CSelection::PrivPostInternalizeSelection(Environment* ev, 
  254.                                             FW_CCloneInfo* cloneInfo, 
  255.                                             FW_EInternalizeResult result)
  256. {
  257. FW_UNUSED(ev);
  258. FW_UNUSED(result);
  259. FW_UNUSED(cloneInfo);
  260.  
  261.     // Nothing to do
  262. }
  263.  
  264. //----------------------------------------------------------------------------------------
  265. //    FW_CSelection::GetPart
  266. //----------------------------------------------------------------------------------------
  267.  
  268. FW_CPart* FW_CSelection::GetPart(Environment *ev) const
  269. {
  270.     return GetPresentation(ev)->GetPart(ev);
  271. }
  272.  
  273. //----------------------------------------------------------------------------------------
  274. //    FW_CSelection::GetSession
  275. //----------------------------------------------------------------------------------------
  276.  
  277. ODSession* FW_CSelection::GetSession(Environment *ev) const
  278. {
  279.     return GetPart(ev)->GetSession(ev);
  280. }
  281.  
  282. //----------------------------------------------------------------------------------------
  283. //    FW_CSelection::IsMouseInDraggableItem
  284. //----------------------------------------------------------------------------------------
  285.  
  286. FW_Boolean FW_CSelection::IsMouseInDraggableItem(Environment* ev, FW_CFrame* frame, const FW_CMouseEvent& theMouseEvent, FW_Boolean inBackground) const
  287. {
  288.     if (IsEmpty(ev))
  289.         return FALSE;
  290.         
  291.     FW_CAcquiredODShape selectionShape = CreateSelectionShape(ev, theMouseEvent.GetFacet(ev), frame);
  292.     
  293.     FW_CPoint where = theMouseEvent.GetMousePosition(ev, FW_CMouseEvent::kFrame);
  294.     frame->GetContentView(ev)->FrameToViewContent(ev, where);
  295.     
  296.     ODPoint odWhere = where;
  297.     return selectionShape->ContainsPoint(ev, &odWhere);        
  298. }
  299.  
  300. //----------------------------------------------------------------------------------------
  301. //    FW_CSelection::UpdateSelectionOnMouseDown
  302. //----------------------------------------------------------------------------------------
  303.  
  304. void FW_CSelection::UpdateSelectionOnMouseDown(Environment* ev, 
  305.                                             const FW_CMouseEvent& mouseEvent,
  306.                                             ODFacet* embeddedFacet,
  307.                                             FW_Boolean inEmbeddedFrameBorder,
  308.                                             FW_Boolean inBackground)
  309. {
  310.     // Don't do anything
  311. }
  312.  
  313. //----------------------------------------------------------------------------------------
  314. //    FW_CSelection::CreateSelectionShape
  315. //----------------------------------------------------------------------------------------
  316.  
  317. ODShape* FW_CSelection::CreateSelectionShape(Environment* ev,  ODFacet* facet,  FW_CFrame* frame) const
  318. {
  319.     return ::FW_CopyAndRelease(ev, facet->AcquireActiveShape(ev, NULL));
  320. }
  321.  
  322. //----------------------------------------------------------------------------------------
  323. //    FW_CSelection::CanSubscribe
  324. //--------------------------------------------------------------------
  325. FW_Boolean FW_CSelection::CanSubscribe(Environment* ev, ODPasteAsMergeSetting& setting)
  326. {
  327.     // Override to allow this selection to become a destination link.
  328.     // Also specify default settings for the PasteAs dialog: 
  329.     //    kODPasteAsMergeOnly, kODPasteAsEmbedOnly, kODPasteAsMerge, kODPasteAsEmbed
  330.     setting = kODPasteAsMergeOnly;    // default is no embedding
  331.  
  332.     return fAllowSubscribe;
  333. }
  334.  
  335. //----------------------------------------------------------------------------------------
  336. //    FW_CSelection::DoFindPublisher
  337. //--------------------------------------------------------------------
  338. FW_CPublishLink* FW_CSelection::DoFindPublisher(Environment* ev)
  339. {
  340.     // Override to search for a publisher that publishes this selection
  341.     return NULL;
  342. }
  343.  
  344. //---------------------------------------------------------------------------------------
  345. //    FW_CSelection::InternalizeData
  346. //---------------------------------------------------------------------------------------
  347. //    Note: Even if I am not an embedding part I still need to call BeginClone/EndClone
  348. //    otherwise the OpernDoc's OriginaleCloneKind property in the draft is not set correctly
  349.  
  350. FW_EInternalizeResult FW_CSelection::InternalizeData(Environment* ev, 
  351.                                                             FW_CFrame* scopeFrame,
  352.                                                             ODStorageUnit* sourceSU, 
  353.                                                             ODCloneKind cloneKind)
  354. {
  355.     ODDraft* fromDraft = sourceSU->GetDraft(ev);
  356.     ODDraft* dstDraft = GetPart(ev)->GetStorageUnit(ev)->GetDraft(ev);
  357.  
  358.     FW_EInternalizeResult result = FW_kInternalizeFailed;
  359.  
  360.     FW_CCloneInfo cloneInfo(ev, fromDraft, scopeFrame, cloneKind);
  361.     
  362.     cloneInfo.BeginClone(ev, dstDraft);
  363.     
  364.     result = PrivHandleInternalizeSelection(ev, sourceSU, &cloneInfo);        
  365.     
  366.     if (result == FW_kInternalizeFailed) 
  367.     {
  368.         cloneInfo.AbortClone(ev);
  369.         return result;
  370.     }
  371.     
  372.     cloneInfo.EndClone(ev);
  373.     
  374.     PrivPostInternalizeSelection(ev, &cloneInfo, result);
  375.     
  376.     return result;
  377. }
  378.     
  379. //---------------------------------------------------------------------------------------
  380. //    FW_CSelection::ExternalizeData
  381. //---------------------------------------------------------------------------------------
  382. //    Note: Even if I am not an embedding part I still need to call BeginClone/EndClone
  383. //    otherwise the OpernDoc's OriginaleCloneKind property in the draft is not set correctly
  384.  
  385. void FW_CSelection::ExternalizeData(Environment* ev, 
  386.                                             FW_CFrame* scopeFrame,
  387.                                             FW_EStorageKinds storageKind, 
  388.                                             ODStorageUnit* destinationSU, 
  389.                                             ODCloneKind cloneKind)
  390. {
  391.     ODDraft* fromDraft = GetPart(ev)->GetStorageUnit(ev)->GetDraft(ev);
  392.     ODDraft* dstDraft = destinationSU->GetDraft(ev);
  393.  
  394.     FW_CCloneInfo cloneInfo(ev, fromDraft, scopeFrame, cloneKind);
  395.     
  396.     cloneInfo.BeginClone(ev, dstDraft);            
  397.     
  398.     PrivHandleExternalizeSelection(ev, storageKind, destinationSU, &cloneInfo);
  399.  
  400.     cloneInfo.EndClone(ev);
  401. }
  402.     
  403.